package com.hom.test;

public class Exam2 {
    public static void main(String[] args) {
        int[] arr = {12,13,41,57,79};
        int value = 13;

        int index = -1;
        int left = 0;
        int right = arr.length-1;
        int mid = (left+right)/2;
        while(left<=right) {
            //找到结束
            if (value == arr[mid]) {
                index = mid;
                break;
            }//没找到
            else if (value > arr[mid]) {
                left = mid + 1;
            } else if (value < arr[mid]) {

                right = mid - 1;
            }
            mid = (left + right) / 2;
        }
        if(index== -1){
            System.out.println(value+"不存在");
        }else{
            System.out.println(value+"的下标是"+index);
        }
    }
}
